package com.xxx.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.xxx.pojo.MenuRole;
import com.xxx.mapper.MenuRoleMapper;
import com.xxx.pojo.RespBean;
import com.xxx.service.IMenuRoleService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author WXH
 * @since 2022-02-23
 */
@Service
public class MenuRoleServiceImpl extends ServiceImpl<MenuRoleMapper, MenuRole> implements IMenuRoleService {

    @Autowired
   private MenuRoleMapper menuRoleMapper;

    /**
     * 更新角色菜单
     *
     * @param rid
     * @param mids
     * @return
     */
    @Override

    public RespBean updateMenuRole(Integer rid, List<Integer> mids) {
        menuRoleMapper.delete(new QueryWrapper<MenuRole>().eq("rid", rid));
        if (mids == null || mids.size() == 0) {
            return RespBean.sucess("更新成功");
        }
        Integer res = menuRoleMapper.batchInset(rid, mids);
        if (res == mids.size()) return RespBean.sucess("批量修改成功》》");
        return RespBean.error("批量修改失败");
    }
}
